package com.mask.im.business.controller.group;

import com.mask.im.business.model.dto.AdminGroupChatMessageDTO;
import com.mask.im.business.common.model.PageResult;
import com.mask.im.business.common.model.RestResponse;
import com.mask.im.business.model.dto.GroupSendMessageDTO;
import com.mask.im.business.model.entity.chat.IMGroupChatMessageDO;
import com.mask.im.business.service.IMGroupChatMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 群聊记录
 *
 * @author jian
 */
@Api(tags = "群聊记录")
@RestController
public class IMGroupChatMessageController {

    @Resource
    private IMGroupChatMessageService groupChatMessageService;


    @ApiOperation("发送消息")
    @PostMapping("/group_chat/send")
    public RestResponse<IMGroupChatMessageDO> sendMessage(@RequestBody GroupSendMessageDTO sendMessageDTO) {
        return groupChatMessageService.sendMessage(sendMessageDTO);
    }

    @ApiOperation("根据群聊id获取群聊信息")
    @GetMapping("/users/groupChatMessage")
    public RestResponse<?> getGroupChatMessage(@RequestParam("groupChatId") Long groupChatId) {
        return groupChatMessageService.getGroupChatMessage(groupChatId);
    }

    @ApiOperation("用户删除自己全部聊天记录")
    @DeleteMapping("/users/groupChatMessage/clearGroupChatMessage/{groupChatId}")
    public RestResponse<String> clearGroupChatMessage(@PathVariable("groupChatId") Long groupChatId) {
        return groupChatMessageService.clearGroupChatMessage(groupChatId);
    }

    @ApiOperation("获取群聊列表")
    @GetMapping("/admin/groupChatMessage")
    public PageResult<AdminGroupChatMessageDTO> groupChatMessage(
            @RequestParam(value = "createTime", required = false) String createTime,
            @RequestParam(value = "groupChatName", defaultValue = "") String groupChatName) {
        return groupChatMessageService.groupChatMessage(createTime, groupChatName);
    }
}

